package com.ruicar.afs.cloud.bizcommon.gps.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ruicar.afs.cloud.bizcommon.gps.feign.GpsOLEFeign;
import com.ruicar.afs.cloud.bizcommon.gps.service.GpsOLEService;
import com.ruicar.afs.cloud.bizcommon.gps.util.GpsConfig;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName GpsOLEServiceImpl
 * @Description: 欧拉GPS接口
 * @Author zyr
 * @Date 2020/6/5
 * @Version V1.0
 **/
@Slf4j
@Service
@Component
@AllArgsConstructor
public class GpsOLEServiceImpl implements GpsOLEService {

    private GpsConfig gpsConfig;
    private GpsOLEFeign gpsOLEFeign;

    /**
     * 新增工单
     *
     * @param json
     * @return
     */
    @Override
    public JSONObject addOrderWithVpsInfos(JSONObject json) {
        //请求头
        Map headers = makeHeader();
        JSONObject result = gpsOLEFeign.addOrderWithVpsInfos(json, headers);
        return result;
    }

    /**
     * 改派工单
     *
     * @param json
     * @return
     */
    @Override
    public JSONObject updateOrderWithVpsInfos(JSONObject json) {
        //请求头
        Map headers = makeHeader();
        JSONObject result = gpsOLEFeign.updateOrderWithVpsInfos(json, headers);
        return result;
    }

    /**
     * 撤销工单
     *
     * @param appcode
     * @return
     */
    @Override
    public JSONObject cancelOrderWithVpsInfos(String appcode) {
        //请求头
        Map headers = makeHeader();
        JSONObject result = gpsOLEFeign.cancelOrderWithVpsInfos(appcode, headers);
        return result;
    }

    /**
     * 工单综合查询
     *
     * @param appcode
     * @return
     */
    @Override
    public JSONObject getAllOrderInfoByAppCode(String appcode) {
        //请求头
        Map headers = makeHeader();
        JSONObject result = gpsOLEFeign.getAllOrderInfoByAppCode(appcode, headers);
        return result;
    }

    /**
     * 获取工单定位信息
     *
     * @param appcode
     * @return
     */
    @Override
    public JSONObject getAllEqPositionsByAppCode(String appcode) {
        //请求头
        Map headers = makeHeader();
        JSONObject result = gpsOLEFeign.getAllEqPositionsByAppCode(appcode, headers);
        return result;
    }

    /**
     * 获取请求头
     *
     * @return
     */
    public Map makeHeader() {
        Map headers = new HashMap<>();
        headers.put("appkey", gpsConfig.getAppkey());
        return headers;
    }

}
